﻿@model cloudscribe.Core.Web.ViewModels.SiteUser.ManageLoginsViewModel
@using cloudscribe.Core.Models
@using cloudscribe.Core.Web
@using Microsoft.Extensions.Localization
@inject SiteContext Tenant
@inject IStringLocalizer<CloudscribeCore> sr
@{ 
    var socFormat = sr["Log in using your {0} account"];
    ViewData["BodyClass"] = "manage-section manage-logins";
}
@functions {
    public string GetIconForLogin(string displayName)
    {
        switch (displayName)
        {
            case "Facebook":
                return "<i class='fa fa-facebook-square' aria-hidden='true'></i>";
            case "Google":
                return "<i class='fa fa-google' aria-hidden='true'></i>";
            case "Twitter":
                return "<i class='fa fa-twitter' aria-hidden='true'></i>";
            case "Microsoft":
                return "<i class='fa fa-windows' aria-hidden='true'></i>";


        }

        return "<i class='fa fa-arrow-circle-right' aria-hidden='true'></i>";
    }
    public string GetDisplayName(string displayName)
    {
        if (displayName == "OpenIdConnect")
        {
            return Tenant.OidConnectDisplayName;

        }

        return displayName;
    }
}

@{
    ViewData["Title"] = sr["Manage your external logins"];
    ViewData["BodyClass"] = "manage-section manage-logins";
    var removeFormat = sr["Remove this {0} login from your account"];
    var loginFormat = sr["Log in using your {0} account"];
}
<h2>@ViewData["Title"]</h2>
<p class="text-success">@ViewData["StatusMessage"]</p>
@if (Model.CurrentLogins.Count > 0)
{
    <h4>@sr["Registered Logins"]</h4>
    <table class="table">
        <tbody>
            @foreach (var account in Model.CurrentLogins)
            {
                <tr>
                    <td>@account.LoginProvider</td>
                    <td>
                        @if (Model.ShowRemoveButton)
                        {
                            <form asp-controller="Manage" asp-action="RemoveLogin" method="post" class="form-horizontal" role="form">
                                <div>
                                    <input namer="LoginProvider" type="hidden" value="@account.LoginProvider" />
                                    <input name="ProviderKey" type="hidden" value="@account.ProviderKey" />
                                    <input type="submit" class="btn btn-default" value='@sr["Remove"]' title="@string.Format(removeFormat, @account.LoginProvider)" />
                                </div>
                            </form>
                        }
                        else
                        {
                            @: &nbsp;
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
@if (Model.OtherLogins.Count > 0)
{
    <h4>@sr["Add another service to log in."]</h4>
    <hr />
    <form asp-controller="Manage" asp-action="LinkLogin" method="post" class="form-horizontal" role="form">
        <div id="socialLoginList">
            <p>
                @foreach (Microsoft.AspNetCore.Authentication.AuthenticationScheme p in Model.OtherLogins)
                {
                    <button type="submit" class="btn btn-default" id="@p.Name" name="provider" value="@p.Name" 
                             title="@string.Format(socFormat,p.DisplayName)">
                        @Html.Raw(GetIconForLogin(p.DisplayName))
                        @GetDisplayName(p.DisplayName)
					</button>
                }
            </p>
        </div>
    </form>
}
